package com.password.desktop.util;

import java.awt.Component;
import java.util.function.Consumer;

import javax.swing.JOptionPane;

/**
 * 弹出框相关工具
 * 
 * @author yzh
 * @date 2020年6月4日
 *
 */
public class MessageUtil {
	public static void showMessage(Component parentComponent, Object message) {
		JOptionPane.showMessageDialog(parentComponent, message);
	}

	public static void confirmMessage(String tip, Consumer<Void> ok, Consumer<Void> no, Consumer<Void> cancel) {
		int showConfirmDialog = JOptionPane.showConfirmDialog(null, tip);
		// 0表示确认
		if (showConfirmDialog == 0 && ok != null) {
			ok.accept(null);
		}
		// 1表示不确认
		if (showConfirmDialog == 1 && no != null) {
			no.accept(null);
		}
		// 2表示取消
		if (showConfirmDialog == 2 && cancel != null) {
			cancel.accept(null);
		}

	}

}
